<?php namespace Phpcmf\Model\Mbdyf;

class Code extends \Phpcmf\Model
{

    public function get_field_code($field, $type, $rt = '') {

        $file = APPPATH.'Models/Field/'.$field['fieldtype'].'.php';
        if (!is_file($file)) {
            return '没有找到此字段类型['.$field['fieldtype'].']的调用方式';
        }

        $name = $rt ? '$'.$rt.'[\''.$field['fieldname'].'\']' : '$'.$field['fieldname'];
        if ($type == 'comment' && $field['fieldname'] == 'inputtime') {
            $time = $rt ? '$'.$rt.'[\''.$field['fieldname'].'\']' : '$'.$field['fieldname'];
        } else {
            $time = $rt ? '$'.$rt.'[\'_'.$field['fieldname'].'\']' : '$_'.$field['fieldname'];
        }

        $fj = '';
        if (in_array($type, ['module', 'form', 'mform']) && $rt && $field['ismain'] == 0) {
            $fj = '<br><br><font color="red">由于本字段属于附表字段，无法在列表或循环中显示，本字段只能在内容页中显示，咨询我QQ提供另类解决方案</font>';
        }

        return str_replace(
            [PHP_EOL, '$value', '$fid', '$time', '$linkname', '$module'],
            ['<br>', $name, $field['id'], $time, $field['setting']['option']['linkage'], $field['setting']['option']['module']],
            file_get_contents($file)
        ).$fj;

    }

    public function get_category_field_code($field, $mid, $id) {

        if ($mid == 'share' || !$mid) {

        } else {

        }

    }


}